<?php include "db.php"; ?>
<?php include "user.php"; ?>
<?php include "input_check.php"; ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>Account Page</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>  
<body>  
<div id="main">

<?php
if(!empty($_POST['email']) && !empty($_SESSION['LoggedIn']) && !empty($_SESSION['User']))
{
	$user = unserialize($_SESSION['User']);
	if(checkEmail($_POST['email'])) {
		$user->setEmail($_POST['email']);
		$_SESSION['User'] = serialize($user);
		echo "<h1>Success</h1>";
		echo "<p>Your Email has been changed. Please <a href=\"account.php\">click here to return to your account page</a>.</p>";
	}
	else {
		echo "<p>Sorry, the new email was invalid. Please <a href=\"email_change.php\">click here to try again</a>.</p>";
	}
}
elseif(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['User']))
{
	$user = unserialize($_SESSION['User']);
	?>
	
	<p>Please input a valid email address</p>
	
	<form method="post" action="email_change.php" name="emailform" id="emailform">
	<fieldset>
		<label for="email">New Email:</label><input type="text" name="email" id="email" /><br><br>
		<input type="submit" name="submit" id="submit" value="submit" />
	</fieldset>
	</form>
	
	<?php
}
else
{
	?>
        
   <h1>Please login in to view this page.</h1>
    
	<form method="post" action="index.php" name="loginform" id="loginform">
	<fieldset>
		<label for="email">Email:</label><input type="text" name="email" id="email" /><br />
		<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
		<input type="submit" name="login" id="login" value="Login" />
	</fieldset>
	</form>
	    
   <?php
}
?>

</div>
</body>
</html>